package me.zhanshi123.vipsystem.permission.impl;

import cn.nukkit.Player;
import me.zhanshi123.vipsystem.Main;
import me.zhanshi123.vipsystem.permission.PermissionHandler;

public class LuckPerms implements PermissionHandler {
    @Override
    public void addPlayerGroup(Player player, String group) {
        handle(player, group, true);
    }

    private void handle(Player player, String group, boolean b) {
        String method = b ? "add" : "remove";
        Main.getInstance().getServer().dispatchCommand(Main.getInstance().getServer().getConsoleSender(), "lp user " + player.getName() + " parent " + method + " " + group);
    }

    @Override
    public void addPlayerGroup(Player player, String group, String world) {
        handleWorld(player, group, world, true);
    }

    private void handleWorld(Player player, String group, String world, boolean b) {
        String method = b ? "add" : "remove";
        Main.getInstance().getServer().dispatchCommand(Main.getInstance().getServer().getConsoleSender(), "lp user " + player.getName() + " parent " + method + " " + group + " world=" + world);
    }

    @Override
    public void removePlayerGroup(Player player, String group) {
        handle(player, group, false);
    }

    @Override
    public void removePlayerGroup(Player player, String group, String world) {
        handleWorld(player, group, world, false);
    }

    @Override
    public String getGroup(Player player) {
        Main.getInstance().getLogger().warning("LuckPerms getGroup Not Supported");
        return "default";
    }
}
